const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}
const throttle = (fn,delay)=>{//节流
  let oldDate = Date.now();
  return function(){
      let args = arguments;
      let newDate = Date.now();
      let that = this;
      if(newDate-oldDate>delay){
          fn.apply(this,args);
          //倘若时间差大于延长时间 就更新一次旧时间
          oldDate = Date.now();
      }
  }
}

module.exports = {
  formatTime,
  throttle:throttle
}
